<?php

include_once 'foyer.class.php';

class Client
{
	protected $login;
	protected $nom;
	protected $prenom;
	protected $ID;
	protected $maison;
	protected $telephone;

	/**
	 * Constructor of class Client.
	 *
	 * @return void
	 */
	public function __construct($m_login, $m_nom, $m_prenom, $m_ID)
	{
		$this->login = $m_login;
		$this->nom = $m_nom;
		$this->prenom = $m_prenom;
		$this->ID = $m_ID;
		
		$this->listeMaison();
		$this->listeTelephone();
	}

	public function __get($name)
	{
		if(property_exists(get_class(), $name))
		{
			return $this->$name;
		}
	}
	
	public function listeMaison()
	{
		try
		{
			$recupMaison = SPDO::pdo()->prepare("SELECT Adresse, Lien FROM Maison, ControleMaison WHERE Maison.ID_Maison = ControleMaison.ID_Maison AND ControleMaison.ID_Utilisateur = :id");
			$recupMaison->execute(array("id" => $this->ID));
				
			if($recupMaison->rowCount() != 0)
			{
				while($result = $recupMaison->fetch(PDO::FETCH_OBJ))
				{
					$this->maison[] = new Foyer($result->Adresse, $result->Lien);
				}
			}
		}
		catch (PDOException $e)
		{
			die($e->getMessage());
		}
	}
	
	public function listeTelephone()
	{
		$this->telephone = array();
		try 
		{
			$recupTel = SPDO::pdo()->prepare("SELECT Telephone.Numero, Sonne, Vol, Blocage, Latitude, Longitude, Date, Suppression, DateVole FROM Telephone, ControleTelephone WHERE ControleTelephone.Numero = Telephone.Numero AND ControleTelephone.ID_Utilisateur = :id");
			$recupTel->execute(array("id" => $this->ID));
			
			while($result = $recupTel->fetch(PDO::FETCH_OBJ))
			{
				$this->telephone[$result->Numero] = new Telephone($result->Numero, $result->Sonne, $result->Vol, $result->Latitude, $result->Longitude, $result->Blocage, $result->Date, $result->Suppression, $result->DateVole);
			}
			
			$recupTel->closeCursor();
		}
		catch(PDOException $e)
		{
			die($e->getMessage());
		}
	}

	// ...

}
